'use strict';

stareal
    .controller("RaidersAllCommentController", function ($scope, $stateParams, $api, $state,$lazyLoader,localStorageService) {
        $scope.reviews = new $lazyLoader("app/viewcomment/goodComments",{good_id:$stateParams.good_id,type:4},true);
        //点赞
        $scope.IsPraiseView = function (commentid,Index,num,from,event){  //tiao
            if (!localStorageService.get('token')) {
                var  rs = "main.raidersallreply-" + JSON.stringify({comment_id:$scope.comment_id});
                var ua = window.navigator.userAgent.toLowerCase();
                if (ua.match(/MicroMessenger/i) == 'micromessenger') {
                    // 正式地址
                    location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?" +
                        // "appid=wxd39f7e740343d507&" +
                        // "redirect_uri=http%3A%2F%2Fwww.mydeershow.com%2Foauth%2Findex" +
                        "appid=wxda73ac8ac7af1261&" +
                        "redirect_uri=http%3A%2F%2Ftest.djx.m.opentickets.cn%2Foauth%2Findex" +
                        "&response_type=code&scope=snsapi_userinfo&state="+encodeURIComponent(rs);

                    // //测试redirect_uri
                    // location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?" +
                    //     "appid=wxd39f7e740343d507&" +
                    //     "redirect_uri=http%3A%2F%2Ft.stareal.cn%2Foauth%2Findex" +
                    //     "&response_type=code&scope=snsapi_userinfo&state=" + encodeURIComponent(rs);
                } else {
                    // location.href = "https://open.weixin.qq.com/connect/qrconnect?" +
                    //     "appid=wx05c47c7db58b03aa&" +
                    //     "redirect_uri=http%3A%2F%2Fwww.stareal.cn%2Fwx%2Foauth%2Fweixin" +
                    //     "&response_type=code&scope=snsapi_login&state=" + encodeURIComponent(rs) + "#wechat_redirect";
                    location.href = "#/main/login/"+encodeURIComponent(rs);
                }
                return false;
            }
            event.stopPropagation()//阻止冒泡
            $api.post("app/viewcomment/praise", {comment_id:commentid,type:4}, true)
                .then(function (ret) {
                    if(from=='detail'){//详情页
                        $scope.reviews[Index].is_praise = !$scope.reviews[Index].is_praise;
                        $scope.reviews[Index].like = parseInt(ret.praise)+num;
                    }
                    if(from=='all'){//全部评论
                        $scope.reviews.items[Index].is_praise = !$scope.reviews.items[Index].is_praise;
                        $scope.reviews.items[Index].like = parseInt(ret.praise)+num;
                    }
                    if(from=='allreplay'){//全部回复
                        $scope.comment.is_praise = !$scope.comment.is_praise;
                        $scope.comment.like = parseInt(ret.praise)+num;
                    }
                    if(from=='commennt'){//我的评论
                        $scope.comments.items[Index].is_praise = !$scope.comments.items[Index].is_praise;
                        $scope.comments.items[Index].like = parseInt(ret.praise)+num;
                    }
                },function (err) {
                    $alert.show(err)
                })
        }
    });